package com.example.peanutsubway.entity;


import com.example.peanutsubway.util.DataConvert;
import java.util.List;

/**
 * @Author：liyangsong
 * @Version：1.0
 * @Date：2021/9/30-16:06
 * @Since:jdk1.8
 * @Description:
 */


public class PageInfo<T> {
    //    当前页
    private Integer nowPage;
    //    每页显示的条数
    private Integer pageNum;
    //   起始索引
    private Integer startIndex;
    //    总条数
    private Integer totalNum;
    //    总页数
    private Integer totalPage;
    //    分页查询到的数据
    private List<T> dataList;


    public List<T> getDataList() {
        return dataList;
    }

    public void setDataList(List<T> dataList) {
        this.dataList = dataList;
    }





    public PageInfo() {
    }

    /**
     * 分页查询信息
     * @param nowPageStr
     * @param pageNumStr
     * @param totalNum
     */
    public PageInfo(String nowPageStr, String pageNumStr, Integer totalNum) {
        Integer nowPage = DataConvert.stringConvertInteger(nowPageStr);
        Integer pageNum = DataConvert.stringConvertInteger(pageNumStr);
        this.nowPage = nowPage <= 0 ? 1 : nowPage;
        this.pageNum = pageNum <= 0 ? 3 : pageNum;
        this.totalNum = totalNum;
        this.totalPage = this.totalNum % this.pageNum == 0 ? this.totalNum / this.pageNum : this.totalNum / this.pageNum + 1;
        this.nowPage = this.nowPage > this.totalPage ? this.totalPage : this.nowPage;
        this.startIndex = (this.nowPage - 1) * this.pageNum;
    }

    public Integer getNowPage() {
        return nowPage;
    }

    public void setNowPage(Integer nowPage) {
        this.nowPage = nowPage;
    }

    public Integer getPageNum() {
        return pageNum;
    }

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }

    public Integer getStartIndex() {
        return startIndex;
    }

    public void setStartIndex(Integer startIndex) {
        this.startIndex = startIndex;
    }

    public Integer getTotalNum() {
        return totalNum;
    }

    public void setTotalNum(Integer totalNum) {
        this.totalNum = totalNum;
    }

    public Integer getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }
}
